package com.cybertooth.dbconvenience.query.columns;

import org.apache.commons.lang.StringUtils;

/**
 * <p></p>
 *
 * @author dnelson
 * @version 1.0
 */
public class UnderscoreToCamelCase implements ColumnNameTransformer {

	// -----------------------------------------------------------------Constructors

	public UnderscoreToCamelCase() {
	}

	// ---------------------------------------------------------------Public Methods

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String transform(String columnName) {
		String[] fieldParts = StringUtils.split(columnName, '_');
		StringBuilder javaFieldName = new StringBuilder(columnName.length());
		for (int i = 0; i < fieldParts.length; ++i) {
			// make the field part completely lowercase
			String fieldPart = fieldParts[i].toLowerCase();
			if (i == 0) {
				// first portion of field is always lowercase
				javaFieldName.append(fieldPart);
			} else {
				// second portion is always capitalized
				javaFieldName.append(StringUtils.capitalize(fieldPart));
			}
		}
		return javaFieldName.toString();
	}
}
